//
//  IM_NewMessageFactory.m
//  BleTestDemo
//
//  Created by cjg on 2019/8/22.
//  Copyright © 2019 cjg. All rights reserved.
//

#import "IM_NewMessageFactory.h"

@implementation IM_NewMessageFactory

// 安全连接
+ (IMTCANMessage *)confirmMessage {
    IM_NewMessageFormat format;
    format.checkType = 1;
    
    IM_NewMessageBody body;
    body.length = 2;
    body.format = format;
    
    Byte byte[2] = {0x00,0x01};
    NSMutableData *data  = [NSMutableData dataWithBytes:byte length:2];
    IMTCANMessage *message = [[IMTCANMessage alloc] initWithBody:body data:data];
    return message;
}

// 标准组
+ (IMTCANMessage *)StandardMessageWithFormat:(IM_NewMessageFormat)format key:(uint8_t)key tab:(uint32_t)tab length:(uint8_t)length source:(uint8_t)source target:(uint8_t)target channel:(uint8_t)channel property:(uint8_t)property para:(NSData *)data {
    
    IM_NewMessageBody body;
    body.format = format;
    body.length = length;
    body.key = key;
    body.tab = tab;
    
    IM_NewStandardDataFormat dataFormat;
    if (format.dataType == 1) {
        dataFormat.channel = channel;
        dataFormat.property = property;
    }else if (format.dataType == 2) {
        dataFormat.target = target;
        dataFormat.channel = channel;
        dataFormat.property = property;
    }else {
        dataFormat.source = source;
        dataFormat.target = target;
        dataFormat.channel = channel;
        dataFormat.property = property;
    }

    IMTCANMessage *message = [[IMTCANMessage alloc] initWithBody:body StandardData:dataFormat data:data];
    return message;
}

// 专用组
+ (IMTCANMessage *)DedicatedMessageWithFormat:(IM_NewMessageFormat)format key:(uint8_t)key tab:(uint32_t)tab length:(uint8_t)length source:(uint8_t)source target:(uint8_t)target cmd:(uint32_t)cmd para:(NSData *)data {
    
    IM_NewMessageBody body;
    body.format = format;
    body.length = length;
    body.key = key;
    body.tab = tab;

    IM_NewDedicatedDataFormat dataFormat;
    
    if (format.dataType == 4) {
        dataFormat.cmd = cmd;
    }else if (format.dataType == 5) {
        dataFormat.target = target;
        dataFormat.cmd = cmd;
    }else {
        dataFormat.source = source;
        dataFormat.target = target;
        dataFormat.cmd = cmd;
    }

    IMTCANMessage *message = [[IMTCANMessage alloc] initWithBody:body DedicatedData:dataFormat data:data];
    return message;
}

// 自由组
+ (IMTCANMessage *)FreedomMessageWithFormat:(IM_NewMessageFormat)format key:(uint8_t)key tab:(uint32_t)tab length:(uint8_t)length para:(NSData *)data {
    IM_NewMessageBody body;
    body.format = format;
    body.length = length;
    body.key = key;
    body.tab = tab;
    
    IMTCANMessage *message = [[IMTCANMessage alloc] initWithBody:body data:data];
    return message;
}

@end
